package com.smart.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.pojo.OutboundBill;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smart.resp.OutboundBillResp;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author lyj
 * @since 2023-05-17
 */
public interface OutboundBillMapper extends BaseMapper<OutboundBill> {

    @Select("select ob.*,\n" +
            "u.username username,\n" +
            "so.title salesOrderTitle,\n" +
            "p.name productName\n" +
            "from outbound_bill ob\n" +
            "left join user u\n" +
            "on ob.user_id=u.id\n" +
            "and u.del_flag=0\n" +
            "left join sales_order so\n" +
            "on ob.sales_order_id=so.id\n" +
            "and so.del_flag=0\n" +
            "left join product p\n" +
            "on ob.product_id=p.id\n" +
            "and p.del_flag=0\n" +
            "where ob.del_flag=0")
    Page<OutboundBillResp> queryPage(Page<OutboundBillResp> page);

    @Select("select ob.*,\n" +
            "u.username username,\n" +
            "so.title salesOrderTitle,\n" +
            "p.name productName\n" +
            "from outbound_bill ob\n" +
            "left join user u\n" +
            "on ob.user_id=u.id\n" +
            "and u.del_flag=0\n" +
            "left join sales_order so\n" +
            "on ob.sales_order_id=so.id\n" +
            "and so.del_flag=0\n" +
            "left join product p\n" +
            "on ob.product_id=p.id\n" +
            "and p.del_flag=0\n" +
            "where ob.del_flag=0\n" +
            "and ob.id=#{id}")
    OutboundBillResp queryByBillId(long id);
}
